﻿using System;
using NHibernate;
using NHibernate.Criterion;

namespace MSP.Data.NHibernate.UserType
{
    public class BitwiseLogicalExpression : LogicalExpression
    {
        private BitwiseLogicalExpression(string propertyName, object value, string op) :
            base(new SimpleExpression(propertyName, (int)value, op),
                Expression.Sql("?", (int)value, NHibernateUtil.Enum(value.GetType())))
        {
        }

        protected override string Op
        {
            get { return "="; }
        }

        public static BitwiseLogicalExpression IsSet(string propertyName, Enum flags)
        {
            return new BitwiseLogicalExpression(propertyName, flags, " & ");
        }
    }
}